-
Notifications
You must be signed in to change notification settings - Fork 191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Colab Jupyter Notebook Demo #1300
Conversation
examples/demo_test.py
Outdated
import sys | ||
|
||
sys.path.insert(0, "./examples/env") | ||
sys.path.insert(0, "./zoo") | ||
import baseline | ||
import policies.keep_lane_agent | ||
|
||
import gym | ||
|
||
from smarts.zoo import registry | ||
from smarts.env.wrappers.episode_logger import EpisodeLogger | ||
from smarts.env.wrappers.record import RecordVideo, RenderVideo | ||
from smarts.core.utils.episodes import episode_range | ||
|
||
# FormatObs should already be applied | ||
env = gym.make("figure_eight-v0") | ||
# gym.wrappers.Monitor | ||
env: gym.Env = RecordVideo(env, frequency=10) | ||
env: gym.Env = RenderVideo(env) | ||
env: gym.Env = EpisodeLogger(env) | ||
|
||
agent = registry.make_agent("zoo.policies:keep-lane-agent-v0") | ||
for episode in episode_range(max_steps=450): | ||
observation = env.reset() | ||
reward, done, info = None, False, None | ||
while episode.register_step(observation, reward, done, info): | ||
action = agent.act(observation) | ||
observation, reward, done, info = env.step(action) | ||
|
||
env.close() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an experiment that works without errors. Further most work will be within the implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The notebook version also works https://colab.research.google.com/github/huawei-noah/SMARTS/blob/ipynb-test-deps/examples/demo_mock.ipynb
d714e18
to
e08cd03
Compare
examples/demo_test.py
Outdated
# FormatObs should already be applied | ||
env = gym.make("figure_eight-v0") | ||
# gym.wrappers.Monitor | ||
env: gym.Env = RecordVideo(env, frequency=10, name="007-render") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will the from smarts.env.wrappers.record import RecordVideo
solution work with vectorized environments?
Suggestion:
- Currently our
env.render()
inhiway_env.py
simply passes. - Move the image rendering to
env.render()
, whenever the camera-sensor is enabled in smarts. - Then, users can use smarts with the video recorders available from and widely used in gym based codes.
- As a result, we will be more gym friendly and we do not need to build and maintain any of our own video recorder.
Examples of existing video recorders:
-
gym
-
sb3
- Callback to display to tensorboard
- Requires tensorboard, torch, moviepy
- VideoRecorderCallback: https://stable-baselines3.readthedocs.io/en/master/guide/tensorboard.html#logging-videos
-
sb3
- Video recorder environment wrapper
- VecVideoRecorder: https://stable-baselines3.readthedocs.io/en/master/_modules/stable_baselines3/common/vec_env/vec_video_recorder.html#VecVideoRecorder
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I was trying to avoid keeping around state for gym.render(..)
.
I believe I could switch the RecordVideo
wrapper to something like CameraRender
to store the state needed pass out render()
frames so that we can use those frameworks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was going about implementing this and found that the gym
version that implements this properly is gym>=0.18
due to this: openai/gym#2139 ...
It conflicts with Colab because annoyingly they start Colab with gym==0.17.3
so it requires a reload to use it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I somewhat still think that trying to please Colab by matching our package versions to that of Colab results in some funny code and funny package versions in setup.py
. It would be better to align our code with other RL libraries instead, and simply reload to update dependencies while using Colab for the time being until there is a better way of using Colab.
It looks like we may have some problems with |
gif_num += 1 | ||
|
||
|
||
def show_notebook_videos(path="videos", height="400px", split_html=""): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Compared to writing our own video/image display code, we should consider writing video/image to tensorboard for display.
%load_ext tensorboard
%tensorboard --logdir <summary_directory>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That might be reasonable. I will try it out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a tensorboard video summary writer example from dreamerv2
code:
https://github.com/danijar/dreamerv2/blob/07d906e9c4322c6fc2cd6ed23e247ccd6b7c8c41/dreamerv2/common/logger.py#L128
examples/demo_test.py
Outdated
from smarts.env.wrappers.record_video import RecordVideo | ||
from smarts.zoo import registry | ||
|
||
if __name__ == "__main__": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps this file can be removed in the final commit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes that is the intention.
examples/demo_mock.ipynb
Outdated
"id": "wkR0YvENQni4" | ||
}, | ||
"source": [ | ||
"**Setup dependencies**" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps we can move this file into SMARTS/examples/env
folder and rename it to SMARTS/examples/env/create_run_visualize.ipynb
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A rename is in order I will leave that to the end when I delete demo_test.py
.
Mock-up of notebook demos.